import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

/// 自定义异常页面
class CaptureErrorWidget extends StatelessWidget {
  final String error;
  final String stack;

  const CaptureErrorWidget({
    Key key,
    this.error,
    this.stack,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("异常信息"),
        centerTitle: true,
        backgroundColor: _initBackgroundColor(),
        leading: IconButton(
          icon: const Icon(Icons.close),
          onPressed: () {
            SystemNavigator.pop(); // replease
          },
        ),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: RichText(
            text: TextSpan(
                style: const TextStyle(color: Colors.black54, fontSize: 12.0),
                children: <TextSpan>[
                  TextSpan(
                      text: this.error ?? "",
                      style: TextStyle(fontWeight: FontWeight.bold)),
                  TextSpan(text: '\n'),
                  TextSpan(
                      text: this.stack ?? "",
                      style: TextStyle(fontWeight: FontWeight.normal)),
                ]),
          ),
        ),
      ),
//      bottomNavigationBar: SafeArea(child: FlatButton.icon(onPressed: onManualReportPress,
//          color: _initBackgroundColor(),
//          textTheme: ButtonTextTheme.accent,
//          icon: const Icon(Icons.send, size: 24.0,),
//          label: const Text('手动上报异常', style: TextStyle(fontSize: 24.0),))),
    );
  }

  static Color _initBackgroundColor() {
    Color result = const Color(0xF0C0C0C0);
    assert(() {
      result = const Color(0xF0900000);
      return true;
    }());
    return result;
  }

  void onManualReportPress() {}
}
